package com.zjpavt.client.util;

import java.io.IOException;
import java.net.InetAddress;

/**
 * 网络检查工具类
 */
public class NetUtil {

    /**
     * 连接服务器超时
     */
    private static final int CONN_TIME_OUT = 3000;

    /**
     * 检查当前网络状态
     *
     * @param hostName ip
     * @return 是否网络状态好
     * @throws IOException
     */
    public static boolean getNetStatus(String hostName) throws IOException {
        return InetAddress.getByName(hostName).isReachable(CONN_TIME_OUT);
    }

    /**
     * 根据域名获取ip
     *
     * @param hostName 域名
     * @return 返回域名ip
     * @throws IOException
     */
    public static String getIPByHostName(String hostName) throws IOException {
        return InetAddress.getByName(hostName).getHostAddress();
    }

}
